package cq.com.cn.dao;

import cq.com.cn.model.BooksModel;
import cq.com.cn.utils.JDBCUtils;

import java.util.List;

public class BooksDao {

    public static final String queryBooksByType="select * from books where bookType = ?";

    public static final String queryBooksAll="select * from books";

    public static final String queryBooksByName="select * from books where bookName like ? ";

    public static final String queryBookById="select * from books where id=? ";
    /**
     *
     * @param type 书籍类别
     * @return 根据书籍的类别来查询书籍
     *
     */
    public List<BooksModel> findBookByType(int type){
        if(type==0)
            return JDBCUtils.findList(BooksModel.class,queryBooksAll,new Object[]{});
        else
            return JDBCUtils.findList(BooksModel.class,queryBooksByType,type);
    }
    /**
     *
     * @param bookName 书籍类别
     * @return 根据书籍的名称来查询书籍
     *
     */
    public List<BooksModel> findBookByName(String bookName) {
        //   赢在影响力
        return JDBCUtils.findList(BooksModel.class,queryBooksByName,"%"+bookName.trim()+"%");
    }

    public BooksModel findBookById(String id){
        return JDBCUtils.findOne(BooksModel.class,queryBookById,id);
    }
}
